package io.dy.runAsync;

import io.dy.utils.CommonUtils;

import java.util.concurrent.CompletableFuture;

/**
 * @author dmj
 * @date 2024年03月01日 下午8:38
 * runAsync 无返回值异步任务
 */
public class RunAsync {

    public static void main(String[] args) {
        //需求: 异步线程读取dy.txt文件 并在异步线程中打印文件内容
        CommonUtils.printThreadLog("main start");
        CompletableFuture.runAsync(()->{
            CommonUtils.printThreadLog("读取文件开始");
            CommonUtils.sleepSecond(2);
            CommonUtils.printThreadLog(CommonUtils.readFile("dy.txt"));
            CommonUtils.printThreadLog("读取文件结束");
        });
        CommonUtils.printThreadLog("here is blocked 3s");
        CommonUtils.sleepSecond(3);
        CommonUtils.printThreadLog("main end");
    }
}
